import { instance } from '../request'

const request = instance

/**
 * 分页获取路由列表
 * @param page 分页页码
 * @param size 分页大小
 * @param sortId 分类id
 * @returns
 */
export const getRoutesListApi = (
  page: number,
  size: number,
  sortId?: string
): PromiseRes<QueryRoutesListItf> =>
  request.get(`/routes/routesList?sortId=${sortId}&size=${size}&page=${page}`)

/**
 * 获取分类下的所有路由
 * @param sortId 分类id
 * @returns
 */
export const getAllSortRoutesApi = (sortId: string): PromiseRes<RouteItf[]> =>
  request.get(`/routes/allSortRoutes?sortId=${sortId}`)

/**
 * 创建页面路由或者修改页面路由信息
 * @param routes  路由信息
 * @param routeId  可选参数，修改路由时可带上，创建时无需
 * @returns
 */
export const setRouteApi = (routes: {
  path: string
  name: string
  component: string
  componentPath: string
  description: string
  isRedirect: 0 | 1
  isNavigation: 0 | 1
  parentId?: string
  sortId?: string
  id?: string
}): PromiseRes => request.post(`/routes/setRoute`, routes)

/**
 * 批量删除页面路由
 * @param routeIdList 路由id列表
 * @returns
 */
export const deleteRoutesApi = (routeIdList: string[]): PromiseRes =>
  request.post('/routes/deleteRoutes', routeIdList)

/**
 * 批量更新路由状态
 * @param routeIdList 路由id 列表
 * @param status 状态 0启用，1禁用
 * @returns
 */
export const updateRoutesStatusAPi = (
  routeIdList: string[],
  status: 0 | 1
): PromiseRes =>
  request.post(`/routes/updateRoutesStatus?status=${status}`, routeIdList)
